<template>
	<view class="content">
		
		<button type="default" @click="test()">测试</button>
		<button type="default" @click="appleLogin()">测试苹果登录</button>
		<button type="default" @click="openRichAlert()">测试RichAlert</button>
		<button type="default" @click="initClick()">初始化</button>
		<button type="default" @click="startLogin()">唤起登录</button>
		<button type="default" @click="checkSigined()">检查登录信息</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'Hello'
			}
		},
		onLoad() {
			var globalEvent = uni.requireNativePlugin('globalEvent');
			globalEvent.addEventListener('myEvent', function(e) {
			  console.log('myEvent'+JSON.stringify(e));
			});
		},
		created(){
			// const params = `#version=v3.3&appId=xxxx&status=true&cookie=true&xfbml=true&autoLogAppEvents=true`;
			//     (function (d, s, id) {
			//       // Load the SDK asynchronously
			//       var js;
			//       var fjs = d.getElementsByTagName(s)[0];
			//       if (d.getElementById(id)) return;
			//       js = d.createElement(s);
			//       js.id = id;
			//       js.src = "https://connect.facebook.net/zh_TW/sdk.js" + params;
			//       fjs.parentNode.insertBefore(js, fjs);
			//     })(document, "script", "facebook-jssdk");
		},
		methods: {
			test(){
				const dcTest = uni.requireNativePlugin('Fengwch-TestModule');
				console.log(dcTest);
				// dcTest.testSyncFunc();
				var t = dcTest.testAsyncFunc({
					name: "unimp",
					age: 1
				},(ret) => {
					console.log(ret);
				});
			},
			appleLogin(){
				uni.login({  
				    provider: 'apple',  
				    success: function (loginRes) {  
						console.log(loginRes);
				        // 登录成功  
				        uni.getUserInfo({  
				            provider: 'apple',  
				            success(res) {  
				                // 获取用户信息成功  
								console.log(res);
				            }  
				        })  
				    },  
				    fail: function (err) {  
				        // 登录失败  
						console.log(err)
				    }  
				});  
			},
			openRichAlert(){
				const dcRichAlert = uni.requireNativePlugin('Fengwch-RichAlert');
				dcRichAlert.show({
				        position: 'bottom',
				        title: "提示信息",
				        titleColor: '#FF0000',
				        content: "<iframe href='https://uniapp.dcloud.io/'></iframe>",
				        contentAlign: 'left',
				        checkBox: {
				            title: '不再提示',
				            isSelected: true
				        },
				        buttons: [{
				                title: '取消'
				            },
				            {
				                title: '否'
				            },
				            {
				                title: '确认',
				                titleColor: '#3F51B5'
				            }
				        ]
				    }, result => {
				        switch (result.type) {
				            case 'button':
				                console.log("callback---button--" + result.index);
				                break;
				            case 'checkBox':
				                console.log("callback---checkBox--" + result.isSelected);
				                break;
				            case 'a':
				                console.log("callback---a--" + JSON.stringify(result));
				                break;
				            case 'backCancel':
				                console.log("callback---backCancel--");
				                break;
				        }
				    });
			},
			initClick() {
				let JYGoogleSignin = uni.requireNativePlugin("JY-GoogleSignin");
				JYGoogleSignin.jy_init({
					client_id: "221707817109-8q2ocumsqa4drnatduld9qnaa3b6jame.apps.googleusercontent.com"
				}, res=> {
					//	这里不会有返回数据
				})
			},
			startLogin() {
				let JYGoogleSignin = uni.requireNativePlugin("JY-GoogleSignin");
				JYGoogleSignin.jy_startLogin(res=> {
					console.log(JSON.stringify(res));
					uni.showToast({
						icon:'none',
						title:JSON.stringify(res)
					})
				})
			},
			checkSigined() {
				let JYGoogleSignin = uni.requireNativePlugin("JY-GoogleSignin");
				JYGoogleSignin.jy_getLastSigned(res=> {
					console.log(JSON.stringify(res));
					uni.showToast({
						icon:'none',
						title:JSON.stringify(res)
					})
				})
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
